package com.ytc.basic.controller;

import com.ytc.basic.domain.Category;
import com.ytc.commons.model.vo.CategoryVo;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.commons.utils.BeanHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ytc.basic.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 课程分类前端控制器
 * </p>
 *
 * @author
 */
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService  categoryService;

    /*
    * 查询课程分类
    * GET /tree-nodes
    * x响应数据ResponseResult<CategoryVo>
    * */
    @GetMapping("/tree-nodes")
    public ResponseResult<CategoryVo> findTreeNodes(){
        return categoryService.findTreeNodes();
    }

    //管理端
    @GetMapping("/list")
    public ResponseResult<List<CategoryVo>> list(){
        return ResponseResult.okResult(categoryService.list());
    }

    /*
    * 根据id查询分类数据
    * @GET /{id}
    * 返回：CategoryVo
    * */
    @GetMapping("/{id}")
    public ResponseResult<CategoryVo> findById(@PathVariable("id")String id){
        Category category = categoryService.getById(id);
        CategoryVo categoryVo = BeanHelper.copyProperties(category, CategoryVo.class);
        return ResponseResult.okResult(categoryVo);
    }
}
